import axios from '~/axios'
import { joinPramas } from './manager'

// 查询列表
export function api_orders_list(form) {
    //如果工单状态不为空，则入参为list；
    //工单状态（1:未派发, 2:已派发,3工程师已接单，4工程师已出发，5:已开始,6施工已结束，7:已回款, 8:工单已完结）
    const paramIo = JSON.parse(JSON.stringify(form));
    if(form.orderStatus != null){
        let status = form.orderStatus
        paramIo.orderStatus = [status]
    }
    let url = '/api/backend/orders/search'
    return axios.post(url, paramIo)
}

// 查询状态常量
export function api_project_constant() {
    return axios.get('/api/backend/projects/get_constants')
}

// update
export function api_orders_update(id, form) {
    let url = '/api/backend/orders/update'
    return axios.post(url, {id, ...form})
}

// add
export function api_orders_add(form) {
    let url = '/api/backend/orders/create'
    return axios.post(url, form)
}

// delete
export function api_orders_delete(id) {
    let url = '/api/backend/orders/delete/' + id
    return axios.post(url, {})
}

// detail
export function api_orders_detail(id) {
    let url = '/api/backend/orders/getOrderInfo?orderId=' + id
    return axios.get(url)
}

// 派单
export function api_orders_dispatch(reqParams) {
    return axios.post('/api/backend/orders/assign', null, {params: reqParams})
}
// 获取评分项
export function api_orders_scoreLabels() {
    return axios.get('/api/backend/order-comment/getLabels')
}
//打分
export function api_orders_postScore(reqBody) {
    return axios.post('/api/backend/order-comment/create', reqBody)
}
// 查看评分
export function api_orders_getScore(orderId) {
    return axios.post('/api/backend/order-comment/search/' + orderId)
}
// 查看日志列表
export function api_orders_logList(reqParams) {
    let finalUrl = joinPramas('/api/backend/orders/searchOrderLogs', reqParams)
    return axios.post(finalUrl)
}

// 根据工单ID查看日志列表
export function api_orders_getLogByOrderId(reqParams) {
    let finalUrl = joinPramas('/api/backend/orders/getLogByOrderId', reqParams)
    return axios.post(finalUrl)
}

// 根据工单ID查看任务安排流程
export function api_orders_getOrderAssign(reqParams) {
    let finalUrl = joinPramas('/api/backend/orders/getOrderAssign', reqParams)
    return axios.post(finalUrl)
}


// 修改日志时间
export function api_orders_log_updateCreateTime(reqBody) {
    return axios.post('/api/backend/orders/updateOrderLog', reqBody)
}
// 查询位置信息
export function api_orders_log_location(reqBody) {
    return axios.post('/api/backend/locations/search', reqBody)
}

// 获取客户评分项
export function api_orders_customerScoreLabels() {
    return axios.get('/api/front/order-comment/getLabels')
}
// 查看客户评分
export function api_orders_getCustomerScore(orderId,sourceType) {
    return axios.post('/api/front/order-comment/search?orderId=' + orderId+'&sourceType=' +sourceType)
}

// 查看附件列表
export function api_orders_getOrderAttachmen(orderId) {
    return axios.get('/api/backend/orders/getOrderAttachmen?orderId=' + orderId)
}

// 上传工单附件
export function api_orders_createOrderAttachmen(paramIo) {
    return axios({
        url: '/api/backend/orders/createOrderAttachmen',
        method: 'post',
        data: paramIo,
        headers: {
            'Content-Type':'multipart/form-data'
        },
        timeout: 3000000
    })
}

// 根据文件id删除工单某个附件
export function api_orders_deleteOrderAttachmen(fileId) {
    return axios.post('/api/backend/orders/deleteOrderAttachmen/' + fileId)
}

// 查看施工档案附件列表
export function api_orders_getOperationAttachmen(orderId) {
    return axios.get('/api/backend/orders/getOperationAttachmen?orderId=' + orderId)
}

// 工单完工统计
export function api_orders_done_statistic(paramIo) {
    let url = '/api/backend/orders/orderStatistic'
    return axios.post(url, paramIo)
}

// 满意度统计
export function api_orders_comment_statistic(paramIo) {
    let url = '/api/backend/orders/commentStatistic'
    return axios.post(url, paramIo)
}

/**
 * 工程师统计
 * @param {*} paramIo 
 */
export function engineerStatistic(paramIo) {
    return axios({
        url: '/api/backend/orders/engineerStatistic',
        method: 'post',
        data: paramIo
    })
}

export function api_orders_getReport(reqParams) {
    let url = '/api/backend/orders/getReport'
    let strUrl = joinPramas(url, reqParams)
    return axios.get(strUrl)
}

export function api_orders_createFile(paramIo) {
    return axios({
        url: '/api/backend/orders/createFile',
        method: 'post',
        data: paramIo,
        headers: {
            'Content-Type':'multipart/form-data'
        },
        timeout: 3000000
    })
}